<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>住院登记</title>
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link id="easyuiTheme" rel="stylesheet" href="static/easyui/themes/ui-cupertino/easyui.css">
<link rel="stylesheet" href="static/easyui/themes/icon.css">
<script type="text/javascript" src="static/js/jquery.cookie.js"></script>
</head>
<body class="easyui-layout" >
<script type="text/javascript">
$(function(){
	//初始化科室下拉列表
	$('#departments').combobox({
	    url:'ljw-departments',//数据源
	    valueField:'departments_id',//实际值
	    textField:'departments_name',//显示值
	    onSelect:function(row){
	    	//初始化第二个下拉列表
	    	$("#doctor").combobox({
	    		url:'cxsbys?ksid='+row["departments_id"],
	    		valueField:"user_id",
	    		textField:"user_name",
	    	}),
	    	//初始化第三个下拉列表
	    	/* $("#nurse").combobox({
	    		url:'ljw-role?did='+row["departments_id"]+'&rid=1',
	    		valueField:"user_id",
	    		textField:"user_name"
	    	}), */
	    	
	    	//初始化第四个下拉列表
	    	$("#bed").combobox({
	    		url:'ljw-bed?did='+row["departments_id"],
	    		valueField:'bed_id',
	    		textField:'bed_number'
	    	});
	    }
	});
	
	//文本框验证
	$.extend($.fn.validatebox.defaults.rules, {    
	    phoneNum: { //验证手机号   
            validator: function(value, param){ 
            	return /^1[34578]\d{9}$/.test(value);
            },    
            message: '请输入正确的手机号码' 
	    },
	    cidNum: {//验证身份证号   
	    	validator: function(value, param){ 
            	return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(value);
            },    
            message: '请输入正确的身份证号' 
	    },
	   isNull: {
			validator: function(value, param){ 
				if($.trim(value)==""){
					return false;
				}
           		return true;
            }, 
		    message: '请输入非空白字符' 
	   } 
	});
	
	//住院通知搜索框
	$("#midText").searchbox({
		searcher:function(value){
			$("#registerForm").form("load",'ljw-medical?mid='+value);
		}
	});
	
	//住院记录搜索框
	$("#hidText").searchbox({
		searcher:function(value){
			initHospital(value);
		}
	});
	
	//清空按钮
	$("#clearHBtn").click(function(){
		$("#registerForm").form("clear");
		$("#mzcardId").textbox("setValue",0);
	});
	
	//确认登记按钮的点击事件
	$("#registerBtn").click(function(){
		$("#registerForm").form({
			url:'ljw-register',
			onSubmit:function(){
				return $(this).form('enableValidation').form('validate');
			},
			success:function(data){
				if(data=="成功"){
					$.messager.alert('提示','登记成功','info');
					$("#registerForm").form("clear");
					$("#mzcardId").textbox("setValue",0);
				}else{
					alert(data);
				}
			}
		});
		$("#registerForm").submit();
	});

	//选项卡点击时刷新表格数据
	 $("#registerTabs").tabs({
		onSelect:function(title){
			if(title=="住院记录"){
				$('#regTable').datagrid('reload'); 
			}
		}
	});  
	
	initHospital("");//住院记录的表格初始化
	
});

//住院记录的表格初始化方法
function initHospital(hid){
	$("#regTable").datagrid({
		url:"ljw-record-hos?hid="+hid,
		fitColumns:true,
		pagination:true,
		singleSelect:true,
		pageSize:"10",
	    pageList:[5,10,15,20],
		columns:[[
			{field:'hospital_id',title:'住 院 号',width:60,halign:'center'},
			{field:'bed_number',title:'床 位',width:60,halign:'center',
				formatter:function(value,row,index){
					return value+"号床";
				}		
			},
			{field:'patient_name',title:'姓 名',width:80,halign:'center'},
			{field:'patient_sex',title:'性 别',width:50,halign:'center'},
			{field:'card_cid',title:'身 份 证 号',width:150,align:'center'},
			{field:'patient_age',title:'年 龄',width:50,halign:'center'},
			{field:'Departments_name',title:'科 室',width:100,halign:'center'},
			{field:'hospital_cash',title:'预 交 押 金',width:100,halign:'center',
				formatter:function(value,row,index){
					return "￥" + value.toFixed(2);
				}	
			},
			{field:'u1',title:'主 治 医 师',width:100,halign:'center'},
			{field:'hospital_time',title:'住 院 时 间',width:180,align:'center',
				formatter:function(value,row,index){
					var time = new Date(value).toJSON();
					var date = new Date(+new Date(time)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'') ;
					return date;
				}
			},
			{field:'hospital_state',title:'住 院 状 态',width:100,halign:'center'}
		]],
	});
}
</script>
<div class="easyui-tabs" id="registerTabs" style="width: 100%;height: 100%;">
	<div title='住院登记' style="padding: 10px 90px;">
		<form id="registerForm" method="post" >
		   <input id="midText" class="easyui-searchbox" data-options="prompt:'住院通知查询'" style="width:160px" >
		   <fieldset style="border-radius: 5px;margin-top:10px;width:900px;border: 1px solid darkseagreen;">
		    	<legend>个人信息</legend>
				<p style="padding-left: 20px;">
					<input name="patientName" class="easyui-textbox" required="required" data-options="label:'姓名：',labelAlign:'right',validType:'isNull'" style="height:28px;padding-left:5px;">
					<select name="patientSex" class="easyui-combobox" panelHeight="auto" required="required"
						data-options="label:'性别：',labelAlign:'right',width:160,editable:false">
						<option value="男">男</option>
						<option value="女">女</option>
					</select>
					<input name="patientAge" class="easyui-numberbox" required="required" data-options="label:'年龄：',labelAlign:'right'" style="height:28px;padding-left:5px;">
					<input name="mzcardPhone" class="easyui-numberbox" required="required" data-options="label:'手机：',labelAlign:'right',validType:'phoneNum'" style="width:220px;height:28px;padding-left:5px;">
					<input id="mzcardId" name="mzcardId" type="hidden" class="easyui-textbox" value="0"/>
				</p>
				<p style="padding-left: 20px;">
					<input name="cardCid" class="easyui-textbox" required="required" data-options="label:'身份证号：',labelAlign:'right',validType:'cidNum'" style="width:280px;height:28px;padding-left:5px;">
					<span style="display: inline-block;width: 30px"></span>
					<input name="homeAddress" class="easyui-textbox" required="required" data-options="label:'家庭住址：',labelAlign:'right',validType:'isNull'" style="width:500px;height:28px;padding-left:5px;margin-left: 30px;">
				</p>
				<p style="padding-left: 20px;"> 
					<select id="departments" name="did" class="easyui-combobox" required="required" editable="false" panelHeight="auto"
					 	data-options="label:'科室：',labelAlign:'right'" style="width:220px;cursor: pointer;">
					</select>		
					
					<select id="doctor" name="user1.userId" class="easyui-combobox" editable="false" required="required" panelHeight="auto"
					 	data-options="label:'医师：',labelAlign:'right'" style="width:180px;cursor: pointer;">
					</select>		
					
					<!-- <select id="nurse" name="user2.userId" class="easyui-combobox" editable="false" required="required" panelHeight="auto"
					 	data-options="label:'护士：',labelAlign:'right'" style="width:180px;cursor: pointer;">
					</select>		 -->
					
					<select id="bed" name="bed_id" class="easyui-combobox"  required="required" editable="false" panelHeight="auto"
					 	data-options="label:'床位：',labelAlign:'right'" style="width:160px;cursor: pointer;">
					</select>		
				</p>
		    </fieldset>
		    <fieldset style="border-radius: 5px;margin-top:20px;width:900px;border: 1px solid darkseagreen;">
		    	<legend> 预交押金</legend>
		    	<p style="padding-left: 20px;">
					<input name="cashMoney" class="easyui-numberbox" required="required" data-options="label:'金额：',labelAlign:'right'" style="height:28px;padding-left:5px;">
					<select name="cashMethod" class="easyui-combobox" panelHeight="auto" editable="false" 
							data-options="label:'交易方式：',labelAlign:'right',width:160">
							<option selected="selected" value="现金">现金</option>
							<option value="微信">微信</option>
							<option value="支付宝">支付宝</option>
					</select>
					<a id="registerBtn" iconCls="icon-save" class="easyui-linkbutton" style="padding:0 5px;margin-left: 60px">保存登记</a>
					<a id="clearHBtn" class="easyui-linkbutton" style="padding:0 5px;margin-left: 30px">清空</a>
				</p>
			</fieldset>
		</form>	
	</div>
	
	<div title='住院记录' style="padding:5px 0;">
		<div style="padding: 5px;background: #dee;">
			<input id="hidText" class="easyui-searchbox" data-options="prompt:'住院号/姓名查询'" 
	    	style="width:160px;height:28px;padding-left:5px;">
		</div>
		<table id="regTable" class="easyui-datagrid" style="height:412px ">
			
		</table>
	</div>
</div>

</body>
</html>